'''
@since: Jan 6, 2012
@author: Chris Giacofei
'''
from xml.etree import ElementTree as ET
#from lxml import etree as ET

def add_line(root, entry):
    
    line_item = ET.SubElement(root, 'log_line')
    
    for key in entry.keys():
        ET.SubElement(line_item, key).text = entry[key]

    return root

def write_log(entry,filename):
    try:
        root = ET.parse(filename).getroot()
    except:
        print('No file found, creating new.')
        root = ET.Element('Log')
        
    new_xml = add_line(root, entry)
    ET.ElementTree(new_xml).write(filename)

    